#include "wizard.h"

static ifly_Wizard_config_t tWizardConf;

void InitWizard(void)
{
	memset(&tWizardConf, 0, sizeof tWizardConf);
	pthread_mutex_init(&tWizardConf.lock, NULL);
}

void RefreshWizardConf(void)
{
	printf("%s\n", __func__);
	pthread_mutex_lock(&tWizardConf.lock);
	GetMode(&tWizardConf.modeInfo);
	if (CUSTOMERID_YA == GetCustomerId())
    {
    	GetDateformatParam(&tWizardConf.dtfmtInfo);
    	GetGpsCheckParam(&tWizardConf.GpsCheck);
    	GetTimingMgr(&tWizardConf.startclosemgr);
    	GetAlarmIn(tWizardConf.Alarmin_Info, MAX_ALARM_IN_NUM);
    }
    else
    {
    	GetConstConfig(&tWizardConf.BusInfo);
    	GetNetServer(&tWizardConf.netserver);
    	GetNet3G4G(&tWizardConf.g3_network);
    	#ifdef TTX_PLATFORM
    	GetTTXParam(&tWizardConf.ttxServer);
    	#endif
    	#if defined JT_PROTOCAL || defined MR9604_FEITIAN
    	GetTransportStdSrv(&tWizardConf.jtServer);
    	#endif

    	GetWIFIParam(&tWizardConf.WifiCfg);
    }

	pthread_mutex_unlock(&tWizardConf.lock);
}

void GetWizardConf(ifly_Wizard_config_t *pConf)
{
	*pConf = tWizardConf;
}

void GetModeWizard(ifly_mode_t *pMode)
{
	*pMode = tWizardConf.modeInfo;
}

void SetModeWizard(ifly_mode_t *pMode)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.modeInfo = *pMode;
	pthread_mutex_unlock(&tWizardConf.lock);
}

void GetStartCloseWizard(ifly_startclost_mgr_t *pStcl)
{
	*pStcl = tWizardConf.startclosemgr;
}

void SetStartCloseWizard(ifly_startclost_mgr_t *pStcl)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.startclosemgr = *pStcl;
	pthread_mutex_unlock(&tWizardConf.lock);
}

void GetAlarmInWizard(ifly_alarmin_t *pAlarm,u8 chn)
{
	if (chn == MAX_ALARM_IN_NUM)
		memcpy(pAlarm, tWizardConf.Alarmin_Info, sizeof (tWizardConf.Alarmin_Info));
	else
		*pAlarm = tWizardConf.Alarmin_Info[chn];
}

void SetAlarmInWizard(ifly_alarmin_t *pAlarm,u8 chn)
{
	pthread_mutex_lock(&tWizardConf.lock);
	//tWizardConf.Alarmin_Info = *pAlarm;
	if (chn == MAX_ALARM_IN_NUM)
	{
		//check_start = 0;
		//check_end = MAX_ALARM_IN_NUM;
		memcpy(tWizardConf.Alarmin_Info, pAlarm, sizeof (tWizardConf.Alarmin_Info));
	}
	else
	{
		//check_start = chn;
		//check_end = chn+1;
		tWizardConf.Alarmin_Info[chn] = *pAlarm;
	}
	pthread_mutex_unlock(&tWizardConf.lock);
}

void GetDateformatParamWizard(u8 *pDtfmt)
{
	*pDtfmt = tWizardConf.dtfmtInfo;
}

void SetDateformatParamWizard(const u8 *pDtfmt)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.dtfmtInfo = *pDtfmt;
	pthread_mutex_unlock(&tWizardConf.lock);
}

void GetGpsCheckParamWizard(ifly_gps_check_t *pGps)
{
	*pGps = tWizardConf.GpsCheck;
}

void SetGpsCheckParamWizard(const ifly_gps_check_t *pGps)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.GpsCheck = *pGps;
	pthread_mutex_unlock(&tWizardConf.lock);
}

void GetBusInfWizard(ifly_const_cofig_t *pInf)
{
	*pInf = tWizardConf.BusInfo;
}

void SetBusInfWizard(const ifly_const_cofig_t *pInf)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.BusInfo = *pInf;
	pthread_mutex_unlock(&tWizardConf.lock);
}

void GetNetServerWizard(ifly_netserver_t *pSrv)
{
	*pSrv = tWizardConf.netserver;
}

void SetNetServerWizard(const ifly_netserver_t *pSrv)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.netserver = *pSrv;
	pthread_mutex_unlock(&tWizardConf.lock);
}

void GetNet3G4GWizard(ifly_net3g4g_t *pG3G4)
{
	*pG3G4 = tWizardConf.g3_network;
}

void SetNet3G4GWizard(const ifly_net3g4g_t *pG3G4)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.g3_network = *pG3G4;
	pthread_mutex_unlock(&tWizardConf.lock);
}

void GetWifiWizard(ifly_wifi_t *pWifi)
{
	*pWifi = tWizardConf.WifiCfg;
}

void SetWifiWizard(const ifly_wifi_t *pWifi)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.WifiCfg = *pWifi;
	pthread_mutex_unlock(&tWizardConf.lock);
}

#ifdef TTX_PLATFORM
void GetTTXParamWizard(ifly_ttx_set_t *pTTXParam)
{
	*pTTXParam = tWizardConf.ttxServer;
}

void SetTTXParamWizard(const ifly_ttx_set_t *pTTXParam)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.ttxServer = *pTTXParam;
	pthread_mutex_unlock(&tWizardConf.lock);
}
#endif

#ifdef JT_PROTOCAL
void GetJTParamWizard(ifly_jt_srv_t *pJTParam)
{
	*pJTParam = tWizardConf.jtServer;
}

void SetJTParamWizard(const ifly_jt_srv_t *pJTParam)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.jtServer = *pJTParam;
	pthread_mutex_unlock(&tWizardConf.lock);
}
#endif

#ifdef MR9604_FEITIAN
void GetTransportStdSrvWizard(ifly_jt_srv_t *pSrv)
{
	*pSrv = tWizardConf.jtServer;
}

void SetTransportStdSrvWizard(const ifly_jt_srv_t *pSrv)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.jtServer = *pSrv;
	pthread_mutex_unlock(&tWizardConf.lock);
}
#endif

#ifdef JT905_PROTOCOL
void GetJT905ParamWizard(ifly_jt905_srv_t *pJTParam)
{
	*pJTParam = tWizardConf.jt905Server;
}

void SetJT905ParamWizard(const ifly_jt905_srv_t *pJTParam)
{
	pthread_mutex_lock(&tWizardConf.lock);
	tWizardConf.jt905Server = *pJTParam;
	pthread_mutex_unlock(&tWizardConf.lock);
}
#endif


